package com.example.park_2306.adapter

import android.widget.LinearLayout
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.CommentEntityItem
import com.example.base.entity.Reply
import com.example.base.utils.GlideUtils
import com.example.park_2306.R

class CommentAdapter:BaseQuickAdapter<CommentEntityItem,BaseViewHolder>(R.layout.item_comment) {
    override fun convert(helper: BaseViewHolder, item: CommentEntityItem) {
        GlideUtils.loadCircle(context,item.userlogo,helper.getView(R.id.comment_image))
        helper.setText(R.id.comment_user,item.nickname)
        helper.setText(R.id.comment_time,item.createtime)
        helper.setText(R.id.comment_msg,item.content)
        //判断是否有子评论

        if(item.replyList!=null&&item.replyList.isNotEmpty()){
            val recyclerView = helper.getView<RecyclerView>(R.id.comment_reply)
            val replyAdapter = ReplyAdapter()
            replyAdapter.data.addAll(item.replyList)
            recyclerView.adapter = replyAdapter
            recyclerView.layoutManager = LinearLayoutManager(context)

        }else{
            helper.getView<LinearLayout>(R.id.ll_reply).isVisible = false
        }
    }
}

class ReplyAdapter:BaseQuickAdapter<Reply,BaseViewHolder>(R.layout.item_reply){
    override fun convert(helper: BaseViewHolder, item: Reply) {
        GlideUtils.loadCircle(context,item.userlogo,helper.getView(R.id.comment_image))
        helper.setText(R.id.comment_user,item.nickname)
        helper.setText(R.id.comment_time,item.createtime)
        helper.setText(R.id.comment_msg,item.content)
    }

}